<template>
    <div class="image-preview-list">
        <div v-for="(image, index) in imageList" :key="index" class="image-item">
            <img :src="image" :alt="`Preview ${index}`" class="image-preview" @click="handlePreview(image)" />
            <!-- 悬停蒙板 -->
            <div class="image-overlay">
                <EyeOutlined class="overlay-icon" title="预览" @click.stop="handlePreview(image)" />
                <DeleteOutlined class="overlay-icon" title="删除" @click.stop="handleRemove(image)" />
            </div>
        </div>
    </div>
</template>

<script setup lang="ts">
import { DeleteOutlined, EyeOutlined } from "@ant-design/icons-vue";

interface Props {
    imageList: string[];
}
const props = withDefaults(defineProps<Props>(), {
    imageList: () => []
});

// const emit = defineEmits(["on-preview", "on-remove"]);
const emit = defineEmits<{
    onPreview: [imageUrlList: string[], imgCurrentIndex: number];
    onRemove: [imageSrc: string];
}>();

const handlePreview = (imageSrc: string) => {
    const index = props.imageList.indexOf(imageSrc);
    emit("onPreview", props.imageList, index);
};

const handleRemove = (imageSrc: string) => {
    emit("onRemove", imageSrc);
};
</script>

<style scoped>
.image-preview-list {
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
}

.image-item {
    position: relative;
    width: 120px;
    height: 120px;
    border-radius: 4px;
    overflow: hidden;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    transition: box-shadow 0.3s ease;
    cursor: pointer;
}

.image-item:hover {
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}

.image-preview {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.image-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.image-item:hover .image-overlay {
    opacity: 1;
}

.overlay-icon {
    color: white;
    font-size: 18px;
    margin: 0 8px;
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    transition: background-color 0.2s ease;
}

.overlay-icon:hover {
    background-color: rgba(255, 255, 255, 0.2);
}
</style>
